IF EXISTS (SELECT * FROM dbo.sysobjects WHERE NAME = 'sp_InsertUSER')
BEGIN
	DROP PROC sp_InsertUSER
END
GO
CREATE PROC sp_InsertUSER
	@IDROLE				INT,
	@USERNAME			VARCHAR(40),
	@PASSWORD			varchar(15),
	@SEX				int,
	@FIRSTNAME			varchar(40),
	@LASTNAME			varchar(40),
	@STATUS				int,
	@ADDRESS			varchar(40),
	@BIRTH_DATE			datetime,
	@Last_updated		datetime,
	@RESULT				INT OUT 
AS
BEGIN
	IF NOT EXISTS (SELECT * FROM SYS_USER WHERE @USERNAME = USERNAME)
	BEGIN
		insert into SYS_USER values(@IDROLE,@USERNAME,@PASSWORD,@FIRSTNAME,@LASTNAME,@SEX,@BIRTH_DATE,@ADDRESS,@STATUS,@Last_updated)
			SET @RESULT = 1
	END
	ELSE 
	BEGIN
		SET @RESULT = 0
	END
END
